<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录界面</title>
    <link rel="shortcut icon" href="/img/xuexi.png">
    <script src="../lib/jquery.min.js"></script>
    <script type="text/javascript" src="./js/common.js"></script>
    <style>
        .clearfix {
            height: 450px;
            width: 450px;
            float: right;
            position: relative;
            top: 111px;
            margin: 0 auto;
            box-sizing: border-box;
            left: -166px;
            text-align: center;
        }

        .clearfix::after {
            content: "";
            display: block;
            clear: both;


        }

        body {
            width: 90%;
            max-width: 900px;
            margin: 0 auto;
        }

        input {
            width: 300px;
            height: 40px;
            margin-top: 30px;
        }


        .shang {
            position: relative;
            top: 27px;
        }
    </style>
    <script>
        $(function () {
            $("#log").click(function () {
                //alert(typeof($("#user").text()))
                $username = $("#user").val();
                $password = $("#pass").val();
                $xuehaoid = $("#xuehao").val();
                // alert($xuehaoid)
                if (!Boolean($username) || !Boolean($password) || !Boolean($xuehaoid)) {
                    alert('不能为空');
                    return;
                };
                var params = `name=${$('#user').val()}&idxuehao=${$('#xuehao').val()}&ps=${$('#pass').val()}`
                //console.log(params);
                var lopara = {
                    name:$('#user').val(),
                    num:$('#xuehao').val(),
                    pwd:$('#pass').val()
                }
                console.log(lopara)

                $.ajax({
                    type: "POST",        //请求方式
                    url: ipurl+`/user/login`,  //服务器地址
                    data: lopara,        //提交给后台的数据  
                    success:function(result){
                        console.log(result)
                        // console.log('请求成功：',data,typeof da)
                        alert(data.body);
                        if (data.code == 200 && data.body == '学生') {
                            window.location.replace("students.html")
                        }
                        if (data.code == 200 && data.body == '老师') {
                            window.location.replace("teacher.html")
                        }
                        if (data.code == 501) {
                            alert('登陆失败');
                        }
                    },
                    err:function(result){
                        console.log('请求失败：', err);
                        alert('登陆失败');
                    }
                });

                // $.ajax({
                //     type: "POST",        //请求方式
                //     url: `http://localhost:8802/login`,  //服务器地址    //服务器地址
                //     // dataType:'json',
                //     // headers:{'Content-Type': 'application/json;charset=utf-8'},
                //     data: params,               //提交给后台的
                // }).then(data => {
                //     // console.log('请求成功：',data,typeof da)
                //     alert(data.body);
                //     if (data.code == 200 && data.body == '学生') {
                //         window.location.replace("students.html")
                //     }
                //     if (data.code == 200 && data.body == '老师') {
                //         window.location.replace("teacher.html")
                //     }
                //     if (data.code == 501) {
                //         alert('登陆失败');
                //     }
                // }, err => {
                //     console.log('请求失败：', err);
                //     alert('登陆失败');
                // });
            })
        })
    </script>
</head>

<body>
    <div class="clearfix">
        <div class="shang">
            <img src="img/denglu.png" alt="登录" style="position: relative; top: 8px;"><br>
            <span>欢迎登录</span>
        </div>

        <input id="user" type="text" placeholder=" 用户名"><br>
        <input id="xuehao" type="text" placeholder=" 学号"><br>
        <input id="pass" type="text" placeholder=" 密码 "><br>
        <input type="button" value=" 登录" id="log"
            style="width: 150px; font: 50px ;text-align: center;background-color: #ccc;">
        <input id="btn_zc" type="button" value="注册"
            style="width: 150px; font: 50px ;text-align: center;background-color: #ccc;">

    </div>
</body>

</html>